<?php

namespace app\controller;

use app\BaseController;
use think\Request;
use think\facade\Filesystem;

class Upload extends BaseController
{
//    public function music_local(Request $request)
//    {
//        $file = $request->file('file');
//        // 上传到本地服务器
//
//        $save_path=env('storage.path').DIRECTORY_SEPARATOR.env('app_name');
//
//        if(!file_exists($save_path)){
//            return JsonData(1001, "上传目录".$save_path."不存在,请创建");
//        }
//
//        $save_file = Filesystem::disk('public')->putFile(env('app_name').'/music', $file);
//        $save_file_url=env('storage.hosts')."/".$save_file;
//
//        return JsonData(SUCCESS_CODE, "上传成功", ['file' => $save_file_url]);
//    }

    public function music(Request $request)
    {
        $type = 'music';

        $file = $request->file('file');
        // 上传到oss服务器
        $save_file = Filesystem::disk('aliyun')->putFile(env('app_name') . '/' . $type, $file);
        $save_file = "/" . $save_file;

        return JsonData(SUCCESS_CODE, "上传成功", [
            'file' => $save_file,
        ]);
    }

    public function image(Request $request)
    {
        $type = 'image';
        $file = $request->file('file');
        // 上传到oss服务器
        $save_file = Filesystem::disk('aliyun')->putFile(env('app_name') . '/' . $type, $file);
        $save_file = "/" . $save_file;

        return JsonData(SUCCESS_CODE, "上传成功", [
            'file' => $save_file,
        ]);
    }
}